<template>
  <div class="score-container">
    <!-- 顶部功能区 -->
    <div class="header-section">
      <div class="filter-group">
        <select class="filter-select">
          <option>全部学期</option>
          <option>2023-2024第一学期</option>
          <option>2023-2024第二学期</option>
        </select>
        <div class="total-score">平均分: {{ avgScore }}</div>
      </div>
      <div class="action-group">
        <button class="login-btn">登录</button>
        <input type="text" class="search-input" placeholder="搜索课程...">
      </div>
    </div>

    <!-- 学生信息区 -->
    <div class="student-info">
      <h2>学生: 张三 (学号: 1001)</h2>
      <p>班级: 计算机科学与技术一班 | 专业排名: 5/120</p>
    </div>

    <!-- 课程成绩表格 -->
    <div class="score-table">
      <table>
        <thead>
          <tr>
            <th>课程编号</th>
            <th>课程名称</th>
            <th>学分</th>
            <th>授课教师</th>
            <th>成绩</th>
            <th>评语</th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="course in courses" :key="course.id" 
              @mouseover="hoverRow = course.id" 
              @mouseleave="hoverRow = null" 
              :class="{ 'hover-row': hoverRow === course.id }">
            <td>{{ course.id }}</td>
            <td>{{ course.name }}</td>
            <td>{{ course.credit }}</td>
            <td>{{ course.teacher }}</td>
            <td>{{ course.score }}</td>
            <td>{{ course.comment }}</td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>

<script>
import { ref, computed } from 'vue';

export default {
  setup() {
    const hoverRow = ref(null);
    const courses = ref([
      { id: 'CS101', name: '高等数学', credit: 4, teacher: '张教授', score: 95, comment: '优秀' },
      { id: 'CS102', name: '大学英语', credit: 3, teacher: '李教授', score: 88, comment: '良好' },
      { id: 'CS103', name: '计算机基础', credit: 2, teacher: '王教授', score: 90, comment: '优秀' },
      { id: 'CS104', name: '数据结构', credit: 4, teacher: '赵教授', score: 92, comment: '优秀' },
      { id: 'CS105', name: '算法分析', credit: 3, teacher: '钱教授', score: 85, comment: '良好' },
      { id: 'CS106', name: '操作系统', credit: 4, teacher: '孙教授', score: 89, comment: '良好' },
      { id: 'CS107', name: '数据库原理', credit: 3, teacher: '周教授', score: 91, comment: '优秀' },
      { id: 'CS108', name: '计算机网络', credit: 4, teacher: '吴教授', score: 87, comment: '良好' },
      { id: 'CS109', name: '软件工程', credit: 3, teacher: '郑教授', score: 93, comment: '优秀' },
      { id: 'CS110', name: '人工智能', credit: 3, teacher: '王教授', score: 90, comment: '优秀' }
    ]);

    const avgScore = computed(() => {
      const sum = courses.value.reduce((acc, cur) => acc + cur.score, 0);
      return (sum / courses.value.length).toFixed(1);
    });

    const maxScore = computed(() => {
      return Math.max(...courses.value.map(item => item.score));
    });

    const minScore = computed(() => {
      return Math.min(...courses.value.map(item => item.score));
    });

    return {
      courses,
      hoverRow,
      avgScore,
      maxScore,
      minScore
    };
  }
};
</script>

<style scoped>
/* 复用PersonalScores.vue的样式，保持一致性 */
.score-container {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.header-section {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 15px;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 15px;
}

.filter-select {
  padding: 8px 12px;
  border-radius: 4px;
  border: 1px solid #ddd;
}

.total-score {
  font-weight: bold;
  color: #2c3e50;
}

.action-group {
  display: flex;
  align-items: center;
  gap: 15px;
}

.login-btn {
  padding: 8px 16px;
  background-color: #42b983;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.login-btn:hover {
  background-color: #3aa876;
}

.search-input {
  padding: 8px 12px;
  border-radius: 4px;
  border: 1px solid #ddd;
  min-width: 200px;
}

.student-info {
  background-color: #f8f9fa;
  padding: 15px;
  border-radius: 8px;
  margin-bottom: 20px;
}

.student-info h2 {
  margin: 0 0 10px 0;
  color: #2c3e50;
}

.student-info p {
  margin: 0;
  color: #666;
}

.score-table {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 12px 15px;
  text-align: left;
  border-bottom: 1px solid #ddd;
}

th {
  background-color: #f2f2f2;
  font-weight: 600;
}

tr:hover {
  background-color: #f5f5f5;
}

.hover-row {
  background-color: #e9f7ef;
}

@media (max-width: 768px) {
  .header-section {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .filter-group, .action-group {
    width: 100%;
    flex-wrap: wrap;
  }
  
  .filter-select, .search-input {
    width: 100%;
    margin-bottom: 10px;
  }
  
  th, td {
    padding: 8px;
    font-size: 14px;
  }
}
</style>